from django.db import models


class Purchase(models.Model):
    """
    采购需求
    """
    STATUS_CHOICES = (
        (0, '未知'),
        (1, '已标记待办'),
        (2, '沟通中'),
        (3, '已成交'),
        (4, '已标记废弃')
    )
    id = models.CharField(max_length=32, primary_key=True, verbose_name="ID")
    province = models.CharField(max_length=32, null=True, blank=True, db_index=True, verbose_name='所属省份')
    keyword = models.CharField(max_length=32, null=True, blank=True, db_index=True, verbose_name='匹配关键词')
    author = models.CharField(max_length=32, blank=True, null=True, verbose_name='发布者')
    budget_price = models.CharField(max_length=16, null=True, blank=True, verbose_name='预算金额')
    district_code = models.CharField(max_length=8, null=True, blank=True, verbose_name='地区代码')
    district_name = models.CharField(max_length=16, null=True, blank=True, db_index=True, verbose_name='地区名称')
    path_name = models.CharField(max_length=16, null=True, blank=True, verbose_name='所属分类', db_index=True)
    procurement_method = models.CharField(max_length=16, blank=True, verbose_name='采购方式')
    project_code = models.CharField(max_length=16, null=True, blank=True, verbose_name='项目代码')
    project_name = models.CharField(max_length=64, null=True, blank=True, verbose_name='项目名称')
    publish_date = models.DateField(null=True, blank=True, verbose_name='发布日期', db_index=True)
    title = models.CharField(max_length=64, null=True, blank=True, db_index=True, verbose_name='标题')
    content = models.TextField(max_length=10240, null=True, blank=True, verbose_name='文章内容')
    url = models.CharField(max_length=255, null=True, blank=True, verbose_name='文章地址')
    expire_flag = models.BooleanField(null=True, blank=True, verbose_name='是否过期')
    expire_at = models.DateTimeField(null=True, blank=True, verbose_name='过期时间')
    implementation_date = models.DateField(null=True, blank=True, verbose_name='实现日期')
    is_gov_purchase = models.BooleanField(null=True, blank=True, verbose_name='是否为政府采购')
    status = models.IntegerField(choices=STATUS_CHOICES, default=0, null=True, blank=True, verbose_name='状态')
    create_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '采购信息'
        verbose_name_plural = verbose_name
        db_table = 'biz_purchase'
        ordering = ['-publish_date']

    def __str__(self):
        return self.title
